package com.naiterui.ehp.ps.sms.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.naiterui.ehp.ps.sms.bean.Signature;
import com.naiterui.ehp.ps.sms.dao.ISignatureDao;
import com.naiterui.ehp.ps.sms.repository.ISignatureRepository;
import com.naiterui.ehp.ps.sms.utils.constants.SmsConstants;

import lombok.RequiredArgsConstructor;

/**
 * 签名持久化实现
 *
 * @author
 * @since 1.0.0
 */
@Component
@RequiredArgsConstructor
public class SignatureDaoImpl implements ISignatureDao {

    private final ISignatureRepository signatureRepository;

    @Override
    public List<Signature> getAll() {
        return signatureRepository.findAll();
    }

    @Override
    public Signature getDefault() {
        return signatureRepository.findFirstByIsDefault((byte)SmsConstants.CODE_Y);
    }

    @Override
    public Signature get(Integer id) {
        return signatureRepository.get(id);
    }

    @Override
    public void saveOrUpdate(Signature signature) {
        if (signature.getId() == null) {
            signatureRepository.save(signature);
        } else {
            signatureRepository.update(signature);
        }
    }

}
